<?php

namespace Modules\Api\Controllers;

use Lib\Http;
use Phalcon\Logger;
use Phalcon\Logger\Adapter\File as FileAdapter;

class CurlController extends ControllerBase {
    /**
     * 模拟联通app登录 -> 失败
     * @return bool
     */
    public function liantongAction() {
        $http   = new Http();
        $url    = 'http://ll.fj10010.com/app/sign!sign.action';
        $cookie = 'accessToken=72A5CE69625D1817fa25257A96E5405CB2; accountId=29B210C53DA3308C2425184AACD3A7EC; JSESSIONID=Yg2f_88gsi7TIhUGc9OZdnakwkd-4VCFYDwdZa1OpMe5db_U4XDY!970968413; REDIS_SESSION_ID=Yg2f_88gsi7TIhUGc9OZdnakwkd-4VCFYDwdZa1OpMe5db_U4XDY!970968413!1484448059168';
        $http->setUrl($url);
        $http->setRefer('http://ll.fj10010.com/app/sign/index.html');
        $http->setUa('Mozilla/5.0 (Linux; HFWSH_USER Android 5.1; m3 note Build/LMY47I) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/40.0.2214.127 Mobile Safari/537.36');
        $http->setCookie($cookie);
        $http->setTimeout(3);
        $content = $http->send();
        $obj     = json_decode($content);
//        var_dump($content);
        if (!$obj instanceof \stdClass) {
            return false;
        }
    }

    public function jiumaAction() {
        set_time_limit(600);
        // ---------------------------
        // 重新进入
        // ---------------------------
        // http://www.ndddpx.com/MyCourse/Default.aspx?infoid=193&courseid=194
        for ($i = 0; $i < 1; ++$i) {
            $http   = new Http();
            $url    = 'http://www.ndddpx.com/Course/CW_Web.aspx?infoid=1289&classid=193&type=wz#a';
            $cookie = 'ASP.NET_SessionId=qzmnix45mivpf2zul5so1j45';
            $http->setUrl($url);
            $http->setRefer('http://www.ndddpx.com/MyCourse/left.aspx?infoid=194&courseid=193');
            $http->setUa('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36');
            $http->setCookie($cookie);
            $http->setTimeout(30);
            $content = $http->send();

            $search = "<span id=\"time1\" style=\"font-size: 18px; font-weight: 900;\">";
            $pos    = strpos($content, $search);

            $time = substr($content, $pos + strlen($search), 8);

            $logger = new FileAdapter(APP_PATH . "/jiuma.log");
            $logger->info($time);

            sleep(290);
        }

        // ---------------------------
        // 获取地址
        // ---------------------------

        $http   = new Http();
        $url    = 'http://www.ndddpx.com/Course/ajax.aspx';
        $post   = [
            "Action"  => "post",
            "infoid"  => 1289,
            "classid" => 193,
            "type"    => "wz",
            "func"    => "cwplay",
        ];
        $cookie = 'ASP.NET_SessionId=qzmnix45mivpf2zul5so1j45';
        $http->setUrl($url);
        $http->setPostFields($post);
        $http->setRefer('http://www.ndddpx.com/MyCourse/left.aspx?infoid=194&courseid=193');
        $http->setUa('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36');
        $http->setCookie($cookie);
        $http->setTimeout(6);
        $http->send();
        sleep(5);
        // ---------------------------
        // 获取地址
        // ---------------------------
        // Iframe|@zzs&|../UpLoad/CW_File/2017001/201700102e.htm
        //$url = $http->send();
        $url = "http://www.ndddpx.com/UPLOAD/CW_FILE/2017001/201700102E.HTM";

        $http   = new Http();
        $cookie = 'ASP.NET_SessionId=qzmnix45mivpf2zul5so1j45';
        $http->setUrl($url);
        $http->setRefer('http://www.ndddpx.com/MyCourse/left.aspx?infoid=194&courseid=193');
        $http->setUa('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36');
        $http->setCookie($cookie);
        $http->setTimeout(5);

        $http->send();
        sleep(5);

        //// ---------------------------
        //// 退出
        //// ---------------------------
        //$http = new Http();
        //
        //$url    = 'http://www.ndddpx.com/UserControl_Org/ajax.aspx';
        //$cookie = 'ASP.NET_SessionId=qzmnix45mivpf2zul5so1j45';
        //$http->setUrl($url);
        //$post = ["func" => "ExitStudy", "Action" => "post"];
        //$http->setPostFields($post);
        //$http->setRefer('http://www.ndddpx.com/Course/CW_Web.aspx?infoid=1289&classid=193&type=wz');
        //$http->setUa('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36');
        //$http->setCookie($cookie);
        //$http->setTimeout(30);
        //$content = $http->send();
        //
        //$logger = new FileAdapter(APP_PATH . "/jiuma.log");
        //$logger->info($content);
        //
        //return false;
    }

    /*

Request URL:http://www.ndddpx.com/UserControl_Org/ajax.aspx
Request Method:POST
Status Code:200 OK
Remote Address:220.161.206.142:80
Referrer Policy:no-referrer-when-downgrade
Response Headers
view source
Cache-Control:private
Content-Encoding:gzip
Content-Length:122
Content-Type:text/html; charset=utf-8
Date:Wed, 14 Feb 2018 02:12:11 GMT
Server:Microsoft-IIS/7.5
Vary:Accept-Encoding
X-AspNet-Version:2.0.50727
X-Powered-By:ASP.NET
Request Headers
view source
Accept-Encoding:gzip, deflate
Accept-Language:zh-CN,zh;q=0.9,en;q=0.8,ja;q=0.7,zh-TW;q=0.6
Connection:keep-alive
Content-Length:26
Content-Type:application/x-www-form-urlencoded
Cookie:ASP.NET_SessionId=qzmnix45mivpf2zul5so1j45
Host:www.ndddpx.com
Origin:http://www.ndddpx.com
Referer:http://www.ndddpx.com/Course/CW_Web.aspx?infoid=1289&classid=193&type=wz
User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36
X-Requested-With:XMLHttpRequest

Form Data
view source
view URL encoded
Action:post
func:ExitStudy

    */

    public function jiumaexistAction() {
        // ---------------------------
        // 退出
        // ---------------------------
        $http = new Http();

        $url    = 'http://www.ndddpx.com/UserControl_Org/ajax.aspx';
        $cookie = 'ASP.NET_SessionId=qzmnix45mivpf2zul5so1j45';
        $http->setUrl($url);
        $post = ["func" => "ExitStudy", "Action" => "post"];
        $http->setPostFields($post);
        $http->setRefer('http://www.ndddpx.com/Course/CW_Web.aspx?infoid=1289&classid=193&type=wz');
        $http->setUa('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36');
        $http->setCookie($cookie);
        $http->setTimeout(30);
        $content = $http->send();

        $logger = new FileAdapter(APP_PATH . "/jiuma.log");
        $logger->info($content);

        return false;
        //// http://www.ndddpx.com/MyCourse/Default.aspx?infoid=193&courseid=194
        //$http = new Http();
        //
        //$url    = 'http://www.ndddpx.com/UserControl_Org/ajax.aspx';
        //$cookie = 'ASP.NET_SessionId=qzmnix45mivpf2zul5so1j45';
        //$http->setUrl($url);
        //$post = ["func" => "CheckNewStudy", "Action" => "post", "id" => "qzmnix45mivpf2zul5so1j45", "name" => "qzmnix45mivpf2zul5so1j45", "type" => "wz"];
        //
        //$http->setPostFields($post);
        //$http->setRefer('http://www.ndddpx.com/Course/CW_Web.aspx?infoid=1289&classid=193&type=wz');
        //$http->setUa('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36');
        //$http->setCookie($cookie);
        //$http->setTimeout(30);
        //$content = $http->send();
        //var_dump($content);
        //die();
        //$logger = new FileAdapter(APP_PATH . "/jiuma.log");
        //$logger->info($content);
        //
        //return false;
    }

    public function testAction() {
        // http://www.ndddpx.com/MyCourse/Default.aspx?infoid=193&courseid=194
        $http = new Http();

        $url    = 'http://www.ndddpx.com/UserControl_Org/ajax.aspx';
        $cookie = 'ASP.NET_SessionId=qzmnix45mivpf2zul5so1j45';
        $http->setUrl($url);
        $post = ["func" => "CheckNewStudy", "Action" => "post", "id" => "qzmnix45mivpf2zul5so1j45", "name" => "qzmnix45mivpf2zul5so1j45", "type" => "wz"];

        $http->setPostFields($post);
        $http->setRefer('http://www.ndddpx.com/Course/CW_Web.aspx?infoid=1289&classid=193&type=wz');
        $http->setUa('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36');
        $http->setCookie($cookie);
        $http->setTimeout(30);
        $content = $http->send();
        var_dump($content);
        die();
        $logger = new FileAdapter(APP_PATH . "/jiuma.log");
        $logger->info($content);

        return false;
    }

    public function logAction() {
        echo file_get_contents(APP_PATH . "/jiuma.log");
        return false;
    }
}
